﻿<!DOCTYPE>
<html>
<head>
    <meta http-equiv="X-UA-Compatible" content="IE=EDGE;IE=11;IE=8,chrome=1" />
    <title>热表批次派工修改</title>
    <link href="/InSiteWebApplication/Content/Easyui/themes/metro/easyui.css" rel="stylesheet" />
    <link href="/InSiteWebApplication/Content/Easyui/custom-easyui.css" rel="stylesheet" />
    <link href="/InSiteWebApplication/Content/Easyui/themes/icon.css" rel="stylesheet" />
</head>
<body>
    <div class="panelSection">
        <div class="easyui-panel " title="查询区域" style="padding: 3px; width: 100%" data-options="closable:false,collapsible:true,minimizable:false,maximizable:false">
            <div style="margin: 3px 0px 3px 3px">
                <div style="float: left">
                    <div class="divLabel" style="margin-bottom: 5px; color: red; font-weight: bold">
                        扫描流水卡：</div>
                    <input id="txtScanContainer" class="easyui-textbox" type="text" style="width: 150px;
                        height: 22px" />
                </div>
                <div style="float: left; margin-left: 10px">
                    <div class="divLabel" style="margin-bottom: 5px">
                        批次名：</div>
                    <input id="txtContainerName" class="easyui-textbox" style="width: 150px; height: 22px" />
                </div>
                <div style="float: left; margin-left: 20px">
                    <button id="btnSearch" class="easyui-linkbutton" data-options="" style="margin-top: 16px;
                        width: 80px">
                        查询</button>
                    <button id="btnReset" class="easyui-linkbutton" data-options="" style="margin-top: 16px;
                        margin-left: 5px; width: 60px">
                        重置</button>
                </div>
                <div style="clear: both">
                </div>
            </div>
        </div>
    </div>
    <div class="panelSection">
        <div class="easyui-panel " title="批次信息" style="padding: 3px; width: 100%" data-options="closable:false,collapsible:true,minimizable:false,maximizable:false">
            <div style="margin: 3px 0px 3px 3px; width: 99%; float: left">
                <table id="gdContainerInfo" class="easyui-datagrid" style="width: 100%; height: 150px"
                    data-options="rownumbers:true">
                </table>
            </div>
        </div>
    </div>
    <div class="panelSection" style="float: left; width: 50%">
        <div class="easyui-panel " title="工步信息" style="padding: 3px; width: 100%" data-options="closable:false,collapsible:true,minimizable:false,maximizable:false">
            <div style="margin: 3px 0px 3px 3px; width: 99%; float: left">
                <table id="gdStepInfo" class="easyui-datagrid" style="width: 100%; height: 322px"
                    data-options="rownumbers:true">
                </table>
            </div>
        </div>
    </div>
    <div class="panelSection" style="float: left; width: 50%">
        <div class="easyui-panel " title="人员修改" style="padding: 3px; width: 100%" data-options="closable:false,collapsible:true,minimizable:false,maximizable:false">
            <div style="margin: 3px 0px 3px 3px; width: 99%; float: left">
                <div style='float: left'>
                    <input id="txtEmpName" class="easyui-textbox" style="width: 150px; height: 22px" />
                </div>
                <div style='float: left'>
                    <a id='btnEmpSearch' href='#' class='easyui-linkbutton' data-options="iconCls:'icon-search'">
                    </a>
                </div>
                <div style='float: left; margin-left: 20px'>
                    <button id="btnEmpCancel" class="easyui-linkbutton l-btn-custom" type="button" style="width: 120px;
                        height: 22px;">
                        任务移交</button>
                </div>
                <table id="gdEmployee" class="easyui-datagrid" style="width: 100%; height: 300px"
                    data-options="rownumbers:true">
                </table>
            </div>
        </div>
    </div>
</body>
</html>
<script src="/InSiteWebApplication/Scripts/CustomPageJs/ReferenceJsLib.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Content/Easyui/jquery.min.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Content/Easyui/jquery.easyui.min.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Content/Easyui/easyui-lang-zh_CN.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Scripts/CustomPageJs/CustomCommon.js" type="text/javascript"></script>
<script type="text/javascript" src="/InSiteWebApplication/Content/Easyui/datagrid-groupview.js"></script>
<script type="text/javascript">
    /*
    创建人：zhangrj
    日期：2023-09-25
    描述：热表批次派工修改页面js
    */
    var page = {
        rootPath: getRootPath(), //网站根路径
        url: getRootPath() + "/Ashx/ContainerStepInfoDispatchHandler.ashx",
        //初始化页面
        init: function () {
            page.bind();
        },
        //页面事件绑定
        bind: function () {
            //批次列表加载
            $("#gdContainerInfo").datagrid({
                columns: [[
                 { field: 'MFGORDERNAME', title: '订单', width: 150 },
                 { field: 'CONTAINERNAME', title: '批次', width: 300 },
                 { field: 'WORKFLOWSTEPNAME', title: '工序', width: 150 },
                 { field: 'QTY', title: '在制数', width: 100 },
                 { field: 'CREATEDATE', title: '开卡日期', width: 120,
                     formatter: function (value, row, index) {
                         if (!isNullOrWhiteSpaceStr(value)) {
                             return dayjs(value).format('YYYY-MM-DD');
                         }
                     }
                 },
                 { field: 'COMBINATENAME', title: '合卡名', width: 150 }
                ]]
            });
            //工步列表加载
            $("#gdStepInfo").datagrid({
                columns: [[
                 { field: 'ck', title: '选择', checkbox: true },
                 { field: 'STEPNO', title: '工步号', width: 120 },
                 { field: 'DESCRIPTION', title: '工步名', width: 150 },
                 { field: 'REPORTEMP', title: '报工人', width: 200, formatter: function (value, row, index) {
                     return "<span title=" + value + ">" + value + "</span>";
                 }
                 }
                ]]
            });
            //人员列表加载
            $("#gdEmployee").datagrid({
                columns: [[
                 { field: 'ck', title: '选择', checkbox: true },
                 { field: 'EMPLOYEENAME', title: '编号', width: 150 },
                 { field: 'FULLNAME', title: '姓名', width: 200 }
                ]]
            });
            //查询按钮
            $('#btnSearch').on("click", function () {
                page.clearPage(false, true, true);
                page.search();
            });
            //清除按钮
            $('#btnReset').on("click", function () {
                page.clearPage(true, true, true);
                page.search();
            });
            //扫描批次事件
            $('#txtScanContainer').textbox({
                onChange: function (n, o) {
                    page.search();
                }
            });
            //人员查询
            $('#btnEmpSearch').on("click", function () {
                page.searchEmp();
            });
            //人员修改
            $('#btnEmpCancel').on("click", function () {
                page.modifyDisEmp();
            });
        },
        //查询
        search: function () {
            var formData = {
                action: "GetRBDispatchModifyDatas",
                scanContainer: $("#txtScanContainer").textbox("getValue"),
                containerName: $("#txtContainerName").textbox("getValue")
            };
            page.post(page.url, formData, true, function (res) {
                if (!res.Result) {
                    displayMessage(res.Message, res.Result);
                    return;
                }
                $("#gdContainerInfo").datagrid('loadData', { rows: res.DBDataSet.dtContainer });
                $("#gdStepInfo").datagrid('loadData', { rows: res.DBDataSet.dtStepInfo });
            });
        },
        //查询人员
        searchEmp: function () {
            var rows = $("#gdContainerInfo").datagrid('getRows');
            if (rows.length === 0) {
                displayMessage("未找到批次", false);
                return;
            }
            var formData = {
                action: "GetEmployeeDatas",
                containerId: rows[0].CONTAINERID,
                workflowstepId: rows[0].WORKFLOWSTEPID,
                employeeName: $("#txtEmpName").textbox("getValue")
            };
            page.post(page.url, formData, true, function (res) {
                if (!res.Result) {
                    displayMessage(res.Message, res.Result);
                    return;
                }
                $("#gdEmployee").datagrid('loadData', { rows: res.DBTable });
            });
        },
        //修改派工人员
        modifyDisEmp: function () {
            page.disablePageBtn();
            var rows = $("#gdContainerInfo").datagrid('getRows');
            if (rows.length === 0) {
                page.enablePageBtn();
                displayMessage("未找到批次信息", false);
                return false;
            }
            var selectedStepInfo = $("#gdStepInfo").datagrid('getChecked');
            if (selectedStepInfo.length === 0) {
                page.enablePageBtn();
                displayMessage("未选择工步", false);
                return false;
            }
            var selectedEmp = $("#gdEmployee").datagrid('getChecked');
            if (selectedEmp.length === 0) {
                page.enablePageBtn();
                displayMessage("未选择人员", false);
                return false;
            }
            var container = rows.map(function (item) {
                return {
                    containerId: item.CONTAINERID,
                    containerName: item.CONTAINERNAME
                }
            });
            var stepInfo = selectedStepInfo.map(function (item) {
                return {
                    stepInfoId: item.STEPINFOID,
                    stepNo: item.STEPNO,
                    stepName: item.DESCRIPTION
                }
            });
            var formData = {
                action: "SaveModifyDispatchData",
                container: JSON.stringify(rows),
                stepInfo: JSON.stringify(stepInfo),
                employee: JSON.stringify(selectedEmp)
            };
            page.post(page.url, formData, true, function (res) {
                if (res.Result) {
                    page.clearPage(false, true, true);
                    page.search();
                }
                page.enablePageBtn();
                displayMessage(res.Message, res.Result);
            });
        },
        //禁用页面按钮
        disablePageBtn: function () {
            //禁用主页面所有按钮
            $("body").find(".easyui-linkbutton").each(function () {
                $(this).linkbutton('disable');
            });
        },
        //恢复页面按钮
        enablePageBtn: function () {
            //恢复主页面所有按钮
            $("body").find(".easyui-linkbutton").each(function () {
                $(this).linkbutton('enable');
            });
        },
        //重置页面（查询，列表，消息）
        clearPage: function (query, list, msg) {
            if (query) {
                $("#txtScanContainer").textbox("clear");
                $("#txtContainerName").textbox("clear");
            }
            if (list) {
                clearEasyuiDataGrid("gdContainerInfo");
                clearEasyuiDataGrid("gdStepInfo");
                clearEasyuiDataGrid("gdEmployee");
                $("#txtEmpName").textbox("clear");
            }
            if (msg) {
                clearMessage();
            }
        },
        //post数据（路径，参数，是否异步，成功返回方法）
        post: function (url, param, async, callback) {
            $.ajax({
                type: "Post",
                url: url,
                data: param,
                cashe: false,
                async: async,
                dataType: "json",
                beforeSend: function () {
                    $.messager.progress({ text: '', msg: '处理中...' });
                },
                success: function (data) {
                    $.messager.progress('close');
                    callback(data);
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    $.messager.progress('close');
                    displayMessage(XMLHttpRequest.responseText, false);
                    page.enablePageBtn();
                }
            });
        }
    }
    $(function () {
        page.init();
    });
</script>
